//
//  ScannerContainerViewModel.swift
//  casdon_swiftUI
//
//  Created by casdon on 2025/5/19.
//

import Foundation
import Combine
import AVFoundation


class ScannerContainerViewModel: ObservableObject {
    @Published  var isLightOn = false
    
    func setTorch() {
        isLightOn.toggle()
        guard let device = AVCaptureDevice.default(for: .video),
              device.hasTorch else {
            print("设备不支持闪光灯")
            return
        }

        do {
            try device.lockForConfiguration()
            device.torchMode = isLightOn ? .on : .off
            device.unlockForConfiguration()
        } catch {
            print("无法使用补光灯: \(error)")
        }
    }
}
